#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: title03最小的调整次数.py 
@version:
@time: 2023/05/29

https://dream.blog.csdn.net/article/details/128985575

3
head add 1
remove
tail add 2
head add 3
remove
remove

> 1
"""
from collections import deque


def solve_method(commands):
    times = 0
    in_ = 0  # 表示要添加的数字，从1到n
    out_ = 0  # 表示删除从1到n的数字
    linked_list = deque()

    for command in commands:
        c = command[0]
        if c == 'h':
            linked_list.appendleft(in_ + 1)
            in_ += 1
        elif c == 't':
            linked_list.append(in_ + 1)
            in_ += 1
        else:
            if out_ + 1 not in linked_list:  # 如果要输出的元素第一个不为out_ + 1 那么调整次数加一，队列重新排序
                continue
            else:
                if linked_list[0] != out_ + 1:
                    times += 1
                    linked_list = deque(sorted(linked_list))
                linked_list.popleft()
                out_ += 1
    return times


n = int(input().strip())
commands = [input().strip() for i in range(n * 2)]
res = solve_method(commands)
print(res)
